Skip to content

Correctly document CTFE behavior of is_null and methods that call is_null. #134325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 22, 2024

Conversation

theemathas
Copy link
Contributor

@theemathas theemathas commented Dec 15, 2024

The "panic in const if CTFE doesn't know the answer" behavior was discussed to be the desired behavior in #74939, and is currently how the function actually behaves.

I intentionally wrote this documentation to allow for the possibility that a panic might not occur even if the pointer is out of bounds, because of #133700 and other potential changes in the future.

This is beta-nominated since const fn is_null stabilization is in beta already but the docs there are wrong, and it seems better to have the docs be correct at the time of stabilization.

@rustbot
Copy link
Collaborator

rustbot commented Dec 15, 2024

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 15, 2024
@tgross35
Copy link
Contributor

Cc @RalfJung

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small wording nit. However I feel like this is also unnecessarily wordy, it kind of says the same thing (might panic for OOB pointers) twice in two paragraphs.

@RalfJung
Copy link
Member

r? @RalfJung

@theemathas
Copy link
Contributor Author

theemathas commented Dec 19, 2024

I have rewritten the comment to be hopefully easier to understand. Hopefully this wording doesn't commit rust to any guarantees that we don't want to make?

The "panic in const if CTFE doesn't know the answer" behavior was discussed to be the desired behavior in rust-lang#74939, and is currently how the function actually behaves.

I intentionally wrote this documentation to allow for the possibility that a panic might not occur even if the pointer is out of bounds, because of rust-lang#133700 and other potential changes in the future.
@theemathas
Copy link
Contributor Author

I have applied RalfJung's proposed wording changes.

I've also edited the "Behavior during const evaluation" heading to "Panics during const evaluation", and made it a level 1 heading, to match the typical "Panics" heading.

Does this need a beta backport, since the is_null methods are const-stabilized in beta?

@theemathas
Copy link
Contributor Author

There are a bunch of const fn methods that call is_null, so I decided to also document those.

@theemathas theemathas changed the title Correctly document is_null CTFE behavior. Correctly document CTFE behavior of is_null and methods that call is_null. Dec 21, 2024
@RalfJung
Copy link
Member

LGTM, thanks :)

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Dec 21, 2024

📌 Commit e6efbb2 has been approved by RalfJung

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 21, 2024
@RalfJung RalfJung added beta-nominated Nominated for backporting to the compiler in the beta channel. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 21, 2024
@bors bors merged commit 3aedae2 into rust-lang:master Dec 22, 2024
6 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Dec 22, 2024
@theemathas theemathas deleted the is_null-docs branch December 22, 2024 02:44
@cuviper cuviper added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jan 2, 2025
@cuviper cuviper mentioned this pull request Jan 2, 2025
@cuviper cuviper modified the milestones: 1.85.0, 1.84.0 Jan 2, 2025
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants